package com.crawler.serializers

import com.crawler.message.{TaskParamMessage, TaskParamListMessage}
import com.esotericsoftware.kryo.Kryo
import com.romix.scala.serialization.kryo.{ScalaCollectionSerializer, ScalaImmutableMapSerializer, ScalaImmutableSetSerializer}

/**
  * Created by tongtao.zhu on 2016/11/30.
  */
class KryoInit {
  def customize(kryo: Kryo): Unit = {
    kryo.register(classOf[TaskParamListMessage], 123)
    kryo.register(classOf[TaskParamMessage], 124)
    // Serialization of Scala sets
    kryo.addDefaultSerializer(classOf[scala.collection.immutable.Set[_]], classOf[ScalaImmutableSetSerializer])
    kryo.addDefaultSerializer(classOf[scala.collection.generic.SetFactory[scala.collection.Set]], classOf[ScalaImmutableSetSerializer])
    // Serialization of Scala maps like Trees, etc
    kryo.addDefaultSerializer(classOf[scala.collection.Map[_, _]], classOf[ScalaImmutableMapSerializer])
    kryo.addDefaultSerializer(classOf[scala.collection.generic.MapFactory[scala.collection.Map]], classOf[ScalaImmutableMapSerializer])
    // Serialization of all Traversable Scala collections like Lists, Vectors, etc
    kryo.addDefaultSerializer(classOf[scala.collection.Traversable[_]], classOf[ScalaCollectionSerializer])
  }
}